
<?php

header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past

require("frmCookie.php");

$iOpcion = $_GET[iOpcion];

switch ($iOpcion)
{
	case 1:
	{
		$mySQL = "SELECT idSucursal FROM almacenes WHERE idAlmacen=" . $_POST['txtOrigenDef'];
		$result = readSQL($mySQL);
		foreach($result as $value)
		{
			$idSucursal = $value['idSucursal'];
		}
		
		$mySQL = "SELECT idAlmacen FROM almacenes WHERE idSucursal=" . $idSucursal . " AND nombre='Transito'";
		$result = readSQL($mySQL);
		foreach($result as $value)
		{
			$idAlmacen = $value['idAlmacen'];
		}
		
		$mySQL = "SELECT O.idOrden, O.nroRemitoEmisor, O.imei, C.nombre, M.nombreComercial, MC.nombre AS MARCA FROM ordenes O, clientes C, modelos M, marcas MC WHERE O.idModelo = M.idModelo AND MC.idMarca = M.idMarca AND C.idCliente = O.idCliente AND O.idAlmacen = " . $_POST[txtOrigenDef] . " ORDER BY O.nroRemitoEmisor";
		$result = readSQL($mySQL);
		
		echo $mySQL;

        foreach($result as $value)
        {
        	$field = "chk" . $value['idOrden'];	
        	
        	if($_POST[$field] == "on")
        	{
        		$mySQL = "UPDATE ordenes SET idAlmacen=" . $idAlmacen . " WHERE idOrden=" . $value['idOrden'];
        		executeSQL($mySQL);
        		
        		$mySQL = "INSERT INTO equipostransito VALUES(";
        		$mySQL = $mySQL . $value['idOrden'] . ", ";
        		$mySQL = $mySQL . $_POST['txtDestinoDef'] . ", ";
        		$mySQL = $mySQL . "'" . $_POST['txtRemitoDef'] . "', ";
        		$mySQL = $mySQL . $_POST['txtOrigenDef'] . ")";
        		executeSQL($mySQL);
        	}
        }
        header("Location: movimientosEquipos.php?iOpcion=1&iMensaje=1");
		break;
	}
}
?>
